//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#pragma package(smart_init)
#pragma resource "*.dfm"

//---------------------------------------------------------------------------
#include "vADoublonRef.h"
//---------------------------------------------------------------------------
__fastcall TListerDoublon::TListerDoublon(const int &nLogiciel,
                                          const int &nVersion,
                                          TComponent* Owner)
    : TForm(Owner)
{

    try {
        dmWebHelp   = NULL;
        m_lDoublons = NULL;

        dmWebHelp = new TdmWebHelp((TComponent*)0);
        m_nLogiciel = nLogiciel;
        m_nVersion  = nVersion;
        m_lDoublons = new TStringList();

        GetDoublons();
        Afficher();

    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);
    }
}
//---------------------------------------------------------------------------
__fastcall TListerDoublon::~TListerDoublon()
{
    try {
        if(dmWebHelp) {delete dmWebHelp; dmWebHelp = NULL;}
        if(m_lDoublons) {delete m_lDoublons; m_lDoublons = NULL;}
    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);
    }
}
//---------------------------------------------------------------------------
void __fastcall TListerDoublon::GetDoublons( void )
{
    TZZMySqlQuery * MaRequete = NULL;
    try {

        MaRequete = new TZZMySqlQuery( (TComponent*)0);
        MaRequete->Database = dmWebHelp->dbWebHelp;

        MaRequete->Sql->Text =  (AnsiString)"SELECT lien_ref "+
                                            "FROM lien "+
                                            "WHERE log_code = "+m_nLogiciel+" and ver_code = "+m_nVersion+" "+
                                            "GROUP BY lien_ref "+
                                            "HAVING count(*)>1";

        MaRequete->Open();
        MaRequete->First();

        while(!MaRequete->Eof) {
            m_lDoublons->Add( asRequete(0) );
            MaRequete->Next();
        }

        MaRequete->Sql->Clear();
        MaRequete->Close();

    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
    if(MaRequete) {delete MaRequete; MaRequete = NULL;}
}
//---------------------------------------------------------------------------
void __fastcall TListerDoublon::Afficher( void )
{
    TZZMySqlQuery * MaRequete = NULL;
    try {
        lvErreur->Items->Clear();
        TListItem  *ListItem;

        MaRequete = new TZZMySqlQuery( (TComponent*)0);
        MaRequete->Database = dmWebHelp->dbWebHelp;

        for(int i=0; i<m_lDoublons->Count; i++) {
            MaRequete->Sql->Text =  (AnsiString)"select lien_ref,"+         //0
                                                        "lien_object,"+     //1
                                                        "lien_ecran "+      //2
                                                "from lien "+
                                                "where (lien_ref = \'"+m_lDoublons->Strings[i]+"\') "+
                                                "and (log_code = "+m_nLogiciel+") and (ver_code = "+m_nVersion+")";

            MaRequete->Open();
            MaRequete->First();

            while(!MaRequete->Eof) {
                ListItem = lvErreur->Items->Add();
                ListItem->SubItems->Add(asRequete(0));
                ListItem->SubItems->Add(asRequete(1));
                ListItem->SubItems->Add(asRequete(2));
                MaRequete->Next();
            }

            MaRequete->Sql->Clear();
        }
        MaRequete->Close();

    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
    if(MaRequete) {delete MaRequete; MaRequete = NULL;}
}
//---------------------------------------------------------------------------
